<template>
  <div v-if="list">
    <div class="card mb-3 shadow-sm" v-for="item in list" :key="item._id">
      <div class="card-body">
        <router-link :to="`/postDetail/${item._id}`" style="text-decoration: none;" class="text-muted">
          <h4>{{item.title}}</h4>
        </router-link>
        <div class="row align-items-center my-3">
          <div class="col-4" v-if="(item.image && typeof item.image !== 'string')">
            <img :src="item.image.url" class="rounded-lg w-100" :alt="item.title">
          </div>
          <p :class="{'col-9': item.image}">{{item.excerpt}}</p>
        </div>
        <span class="text-muted">{{item.createdAt}}</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import { PostProps } from '../store'

export default defineComponent({
  name: 'PostList',
  props: {
    list: {
      required: true,
      type: Array as PropType<PostProps[]>
    }
  }
})
</script>
